Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reachdown

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reachdown

Get the inner db of an (abstract-)level(up|down) onion

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

reachdown

Get the inner db of an (abstract-)level(up|down) onion.
Useful for modules like subleveldown to peel off redundant layers.

npm status node Travis build status JavaScript Style Guide

Example

const reachdown = require('reachdown')
const db = require('level')('example')

Get the innermost db, which in this case is a leveldown instance in node or level-js in browsers:

const down = reachdown(db)

Get a specific layer by type:

const enc = reachdown(db, 'encoding-down')
const down = reachdown(enc)
const levelup = reachdown(db, 'levelup') // levelup === db

Use a visitor function:

const down = reachdown(db, function (db, type) {
  return db.someProperty && type !== 'levelup'
})

API

db = reachdown(db[, visit][, strict = false])

The db argument is required and must be a recent-ish levelup, abstract-leveldown or subleveldown instance. The visit argument can be:

  • A string, to find the first db with a matching type
  • A function, to find the first db for which visit returns a truthy value
  • Omitted or falsy, to find the innermost db.

If visit is non-falsy and no matching db is found, reachdown returns null unless strict is false in which case it returns the innermost db.

bool = reachdown.is(db, visit)

Utility to determine the type of db without reaching down. The visit argument is the same as above, i.e. a string or a function. Example:

if (reachdown.is(db, 'levelup')) {
  // ..
}

Which is the same as the following, except that reachdown.is(..) also works on older versions that don't have a type property:

if (db.type === 'levelup') {
  // ..
}

Supported Types

  • levelup (>= 0.0.2 only if db is open, otherwise >= 2.0.0)
  • encoding-down (>= 1)
  • deferred-leveldown (>= 0.3.0 only if db is open, otherwise >= 2.0.0)
  • subleveldown (>= 4)
  • multileveldown (TBD)
  • Yours?

Implementations of abstract-leveldown can declare a type like so:

MyLeveldown.prototype.type = 'my-leveldown'

So that consumers can find that layer:

var down = MyLeveldown()
var db = levelup(down)

reachdown(db, 'my-leveldown') === down

Install

With npm do:

npm install reachdown

License

MIT © 2019-present Vincent Weevers

Keywords

FAQs

Package last updated on 04 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc